﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace System.Web {
	public static class HttpApplicationStateExtensions {

		public static void RegisterApplicationStaticServerFolder(this HttpApplicationState application, string foldername) {

			if (application.GetUseLock("app_static_server_folder") != null)
				throw new DuplicateNameException("app_static_server_folder");

			application.Lock();
			application.Add("app_static_server_folder", foldername);
			application.UnLock();
		}

		public static T GetRequiredValue<T>(this HttpApplicationState application, string name) where T : class {
			object value = application.GetUseLock(name);
			if (value == null) {
				//throw new ConfigSettingMissingException(name);
				throw new Exception();
			}

			return value as T;
		}

		public static object GetUseLock(this HttpApplicationState application, string name) {
			application.Lock();
			object value = application.Get(name);
			application.UnLock();

			return value;
		}
	}
}